/**
 * 邀请
 */
class InviteItemUI extends BaseComp{
    private btn_add:BaseButton;
    private lb_tips:eui.Label;
    private img_icon:eui.Image;
    private group_head:eui.Group;
    private img_head:eui.Image;
    private img_mask:eui.Image;
    private lb_count:eui.Label;
    constructor()
    {
        super('InviteItemView')
    }

    public init()
    {

    }

    public initUI(data)
    {
        if(data)
        {
            this.data = data;
            let award = data.item_info;
            let item_info = ResourceUtil.instance().parseSignleAward(award);
            let role_info = data.role_info;
            if(item_info)
            {
                let name = item_info.itemData.name;
                this.img_icon.source = item_info.itemIcon;
                this.lb_count.text = `x${item_info.itemNum}`;
                this.img_icon.anchorOffsetX = this.img_icon.texture.textureWidth >> 1;
                this.img_icon.anchorOffsetY = this.img_icon.texture.textureHeight >> 1;
     
                if(item_info.itemData.type == 3)
                {
                    //武器
                    this.img_icon.scaleX = this.img_icon.scaleY = 0.5;
                    this.lb_tips.text = StringUtil.getSwfLangStr('tips_7');
                }
                else if(item_info.itemData.type == 2)
                {
                    //三发和屠龙
                    this.img_icon.scaleX = this.img_icon.scaleY = 0.8;
                    this.lb_tips.text = StringUtil.getSwfLangStrVar('tips_6',[item_info.itemNum,name]);
                }
                else
                {
                    //金币钻石
                    this.lb_tips.text = StringUtil.getSwfLangStrVar('tips_5',[name,item_info.itemNum]);
                }
            }
            if(role_info)
            {
                this.btn_add.visible = false;
                let name = role_info.nick_name ? role_info.nick_name : '神秘用户';
                let url = role_info.avatar_url;
                this.group_head.visible = true;
                this.lb_tips.text = name + '帮你助力过了哦~';
                this.img_head.width = this.img_head.height = 76;
                if(url && url != '')
                {
                    this.img_head.source = url;
                    this.img_head.mask = this.img_mask;
                }
            }
            else
            {
                this.btn_add.redPoint = true;
            }
        }
    }

    public addEvent()
    {
        this.btn_add.addTapHandler(this.invite, this);
    }

    protected invite()
    {
        SharePrase.instance().requestOneAdvertisement({type:ShareId.invite});
    }

    public removeEvent()
    {
        this.btn_add.removeTapHandler();
    }

    public clear()
    {
        super.clear();
    }
}

window['InviteItemUI'] = InviteItemUI;